package com.mfangsoft.zhuangjialong.integration.newGift.service.impl;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.mfangsoft.zhuangjialong.common.context.UserContext;
import com.mfangsoft.zhuangjialong.common.model.Page;
import com.mfangsoft.zhuangjialong.integration.newGift.mapper.NewGiftMapper;
import com.mfangsoft.zhuangjialong.integration.newGift.service.NewGiftService;
import com.mfangsoft.zhuangjialong.integration.user.model.UserEntity;

@Service
public class NewGiftServiceImpl implements NewGiftService{
	
	@Autowired
	private NewGiftMapper newGiftMapper;

	@Override
	public Page<Map<String, Object>> selectNewGiftActivityPage(Page<Map<String, Object>> page) {
		UserEntity currentUser = UserContext.getCurrentUser();
		if(currentUser.getId() == 153){
			List<Map<String,Object>> list = newGiftMapper.selectNewGiftActivityPage(page);
			page.setData(list);
		}
		if(currentUser.getUser_level() == 3){
			Map<String,Object> map = (Map<String,Object>)page.getParam();
			List<Long> creator =  newGiftMapper.selectTowUserByUserId(currentUser.getId());
			map.put("creatorIds", creator);
			page.setParam(map);
			List<Map<String,Object>> list = newGiftMapper.selectNewGiftActivityPage(page);
			page.setData(list);
		}
		if(currentUser.getUser_level() == 2){
			Map<String,Object> map = (Map<String,Object>)page.getParam();
			List<Long> creator = new ArrayList<Long>();
			creator.add(currentUser.getId());
			map.put("creatorIds", creator);
			page.setParam(map);
			List<Map<String,Object>> list = newGiftMapper.selectNewGiftActivityPage(page);
			page.setData(list);
		}
		if(currentUser.getUser_level() == 1){
			Map<String,Object> map = (Map<String,Object>)page.getParam();
			Long twoLevleUserId = newGiftMapper.selectTwoByOneLevelUserId(currentUser.getId());
			List<Long> creator = new ArrayList<Long>();
			creator.add(twoLevleUserId);
			map.put("creatorIds", creator);
			page.setParam(map);
			List<Map<String,Object>> list = newGiftMapper.selectNewGiftActivityPage(page);
			page.setData(list);
		}
		return page;
	}

	@Override
	public List<Map<String,Object>> selectNewGiftActivityList() {
		Long user_id = UserContext.getCurrentUserId();
		List<Map<String,Object>> list = newGiftMapper.selectNewGiftActivityList(user_id);
		return list;
	}

	

}
